﻿Imports System.Collections.Generic
Public Class ucAdvComboBox
    Private comboList As New List(Of comboItem)
    Public getText As String
    Public getValue As String
    Public Event SelectedIndexChanged()
    Const MaxHeight As Integer = 21

    Public Overrides Property MaximumSize() As Drawing.Size
        Get
            Return New Drawing.Size(MyBase.MaximumSize.Width, MaxHeight)
        End Get
        Set(ByVal value As Drawing.Size)
            MyBase.MaximumSize = New Drawing.Size(value.Width, MaxHeight)
        End Set
    End Property

    Public Overrides Property MinimumSize() As Drawing.Size
        Get
            Return New Drawing.Size(MyBase.MinimumSize.Width, MaxHeight)
        End Get
        Set(ByVal value As Drawing.Size)
            MyBase.MinimumSize = New Drawing.Size(value.Width, MaxHeight)
        End Set
    End Property


    Public Sub initialize(dtSource As DataTable, Text As String, Value As String, TextDefault As String)
        cmb.Items.Clear()
        comboList.Clear()
        If TextDefault <> "" Then comboList.Add(New comboItem("- " & TextDefault & " -", ""))
        cmb.Sorted = True
        If (dtSource.Rows.Count > 0) Then
            Dim dr As DataRow
            For Each dr In dtSource.Rows
                comboList.Add(New comboItem(dr(Text), dr(Value)))
            Next
            cmb.DataSource = comboList
            cmb.DisplayMember = "Text"
            cmb.ValueMember = "Value"
        End If
    End Sub

    Private Sub cmb_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmb.SelectedIndexChanged
        getText = cmb.SelectedItem.ToString()
        getValue = cmb.SelectedValue.ToString()
        RaiseEvent SelectedIndexChanged()
    End Sub
End Class
